<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/xhtml;charset=utf-8" http-equiv="Content-Type"/>
<meta content="IE=9" http-equiv="X-UA-Compatible"/>
<meta content="Doxygen 1.8.13" name="generator"/>
<title>OpenCV: Image file reading and writing</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon"/>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script src="../../jquery.js" type="text/javascript"></script>
<script src="../../dynsections.js" type="text/javascript"></script>
<script src="../../tutorial-utils.js" type="text/javascript"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script src="../../search/searchdata.js" type="text/javascript"></script>
<script src="../../search/search.js" type="text/javascript"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js" type="text/javascript"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css"/>
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellpadding="0" cellspacing="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
    <span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script src="../../menudata.js" type="text/javascript"></script>
<script src="../../menu.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow" onkeydown="return searchBox.OnSearchSelectKey(event)" onmouseout="return searchBox.OnSearchSelectHide()" onmouseover="return searchBox.OnSearchSelectShow()">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe frameborder="0" id="MSearchResults" name="MSearchResults" src="javascript:void(0)">
</iframe>
</div>
<div class="header">
  <div class="summary">
<a href="#groups">Modules</a> |
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Image file reading and writing</div>  </div>
</div><!--header-->
<div class="contents">
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="groups"></a>
Modules</h2></td></tr>
<tr class="memitem:da/d0a/group__imgcodecs__c"><td align="right" class="memItemLeft" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d0a/group__imgcodecs__c.html">C API</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:d8/d6a/group__imgcodecs__flags"><td align="right" class="memItemLeft" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d8/d6a/group__imgcodecs__flags.html">Flags used for image file reading and writing</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:d2/d92/group__imgcodecs__ios"><td align="right" class="memItemLeft" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d2/d92/group__imgcodecs__ios.html">iOS glue</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:dc/d7e/group__imgcodecs__macosx"><td align="right" class="memItemLeft" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/d7e/group__imgcodecs__macosx.html">MacOS(OSX) glue</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga0c3f60f18ed3a139e5a9926f9315e3bc"><td align="right" class="memItemLeft" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/da8/group__imgcodecs.html#ga0c3f60f18ed3a139e5a9926f9315e3bc">cv::haveImageReader</a> (const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp;filename)</td></tr>
<tr class="memdesc:ga0c3f60f18ed3a139e5a9926f9315e3bc"><td class="mdescLeft"> </td><td class="mdescRight">Returns true if the specified image can be decoded by OpenCV.  <a href="../../d4/da8/group__imgcodecs.html#ga0c3f60f18ed3a139e5a9926f9315e3bc">More...</a><br/></td></tr>
<tr class="separator:ga0c3f60f18ed3a139e5a9926f9315e3bc"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga0ca4e24f5435a81dfeec720a6e32d852"><td align="right" class="memItemLeft" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/da8/group__imgcodecs.html#ga0ca4e24f5435a81dfeec720a6e32d852">cv::haveImageWriter</a> (const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp;filename)</td></tr>
<tr class="memdesc:ga0ca4e24f5435a81dfeec720a6e32d852"><td class="mdescLeft"> </td><td class="mdescRight">Returns true if an image with the specified filename can be encoded by OpenCV.  <a href="../../d4/da8/group__imgcodecs.html#ga0ca4e24f5435a81dfeec720a6e32d852">More...</a><br/></td></tr>
<tr class="separator:ga0ca4e24f5435a81dfeec720a6e32d852"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga26a67788faa58ade337f8d28ba0eb19e"><td align="right" class="memItemLeft" valign="top"><a class="el" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/da8/group__imgcodecs.html#ga26a67788faa58ade337f8d28ba0eb19e">cv::imdecode</a> (<a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">InputArray</a> buf, int flags)</td></tr>
<tr class="memdesc:ga26a67788faa58ade337f8d28ba0eb19e"><td class="mdescLeft"> </td><td class="mdescRight">Reads an image from a buffer in memory.  <a href="../../d4/da8/group__imgcodecs.html#ga26a67788faa58ade337f8d28ba0eb19e">More...</a><br/></td></tr>
<tr class="separator:ga26a67788faa58ade337f8d28ba0eb19e"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga5a0acefe5cbe0a81e904e452ec7ca733"><td align="right" class="memItemLeft" valign="top"><a class="el" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/da8/group__imgcodecs.html#ga5a0acefe5cbe0a81e904e452ec7ca733">cv::imdecode</a> (<a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">InputArray</a> buf, int flags, <a class="el" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> *dst)</td></tr>
<tr class="separator:ga5a0acefe5cbe0a81e904e452ec7ca733"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga461f9ac09887e47797a54567df3b8b63"><td align="right" class="memItemLeft" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/da8/group__imgcodecs.html#ga461f9ac09887e47797a54567df3b8b63">cv::imencode</a> (const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp;ext, <a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">InputArray</a> img, std::vector&lt; <a class="el" href="../../d1/d1b/group__core__hal__interface.html#ga65f85814a8290f9797005d3b28e7e5fc">uchar</a> &gt; &amp;buf, const std::vector&lt; int &gt; &amp;params=std::vector&lt; int &gt;())</td></tr>
<tr class="memdesc:ga461f9ac09887e47797a54567df3b8b63"><td class="mdescLeft"> </td><td class="mdescRight">Encodes an image into a memory buffer.  <a href="../../d4/da8/group__imgcodecs.html#ga461f9ac09887e47797a54567df3b8b63">More...</a><br/></td></tr>
<tr class="separator:ga461f9ac09887e47797a54567df3b8b63"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga288b8b3da0892bd651fce07b3bbd3a56"><td align="right" class="memItemLeft" valign="top"><a class="el" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">cv::imread</a> (const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp;filename, int flags=<a class="el" href="../../d8/d6a/group__imgcodecs__flags.html#gga61d9b0126a3e57d9277ac48327799c80af660544735200cbe942eea09232eb822">IMREAD_COLOR</a>)</td></tr>
<tr class="memdesc:ga288b8b3da0892bd651fce07b3bbd3a56"><td class="mdescLeft"> </td><td class="mdescRight">Loads an image from a file.  <a href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">More...</a><br/></td></tr>
<tr class="separator:ga288b8b3da0892bd651fce07b3bbd3a56"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga4dd47c9ae3d55cc42286cff005825e31"><td align="right" class="memItemLeft" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/da8/group__imgcodecs.html#ga4dd47c9ae3d55cc42286cff005825e31">cv::imreadmulti</a> (const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp;filename, std::vector&lt; <a class="el" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &gt; &amp;mats, int flags=<a class="el" href="../../d8/d6a/group__imgcodecs__flags.html#gga61d9b0126a3e57d9277ac48327799c80ab6573b69300c092b61800222fe555953">IMREAD_ANYCOLOR</a>)</td></tr>
<tr class="memdesc:ga4dd47c9ae3d55cc42286cff005825e31"><td class="mdescLeft"> </td><td class="mdescRight">Loads a multi-page image from a file.  <a href="../../d4/da8/group__imgcodecs.html#ga4dd47c9ae3d55cc42286cff005825e31">More...</a><br/></td></tr>
<tr class="separator:ga4dd47c9ae3d55cc42286cff005825e31"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gabbc7ef1aa2edfaa87772f1202d67e0ce"><td align="right" class="memItemLeft" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">cv::imwrite</a> (const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp;filename, <a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">InputArray</a> img, const std::vector&lt; int &gt; &amp;params=std::vector&lt; int &gt;())</td></tr>
<tr class="memdesc:gabbc7ef1aa2edfaa87772f1202d67e0ce"><td class="mdescLeft"> </td><td class="mdescRight">Saves an image to a specified file.  <a href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">More...</a><br/></td></tr>
<tr class="separator:gabbc7ef1aa2edfaa87772f1202d67e0ce"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga506e85114c8b4340bb12eca5080205d2"><td align="right" class="memItemLeft" valign="top">static bool </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/da8/group__imgcodecs.html#ga506e85114c8b4340bb12eca5080205d2">cv::imwritemulti</a> (const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp;filename, <a class="el" href="../../dc/d84/group__core__basic.html#ga606feabe3b50ab6838f1ba89727aa07a">InputArrayOfArrays</a> img, const std::vector&lt; int &gt; &amp;params=std::vector&lt; int &gt;())</td></tr>
<tr class="separator:ga506e85114c8b4340bb12eca5080205d2"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<a id="details" name="details"></a><h2 class="groupheader">Detailed Description</h2>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga0c3f60f18ed3a139e5a9926f9315e3bc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga0c3f60f18ed3a139e5a9926f9315e3bc">◆ </a></span>haveImageReader()</h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool cv::haveImageReader </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp; </td>
          <td class="paramname"><em>filename</em></td><td>)</td>
          <td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>retval</td><td>=</td><td>cv.haveImageReader(</td><td class="paramname">filename</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&gt;</code></p>
<p>Returns true if the specified image can be decoded by OpenCV. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filename</td><td>File name of the image </td></tr>
  </table>
  </dd>
</dl>
</div>
</div>
<a id="ga0ca4e24f5435a81dfeec720a6e32d852"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga0ca4e24f5435a81dfeec720a6e32d852">◆ </a></span>haveImageWriter()</h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool cv::haveImageWriter </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp; </td>
          <td class="paramname"><em>filename</em></td><td>)</td>
          <td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>retval</td><td>=</td><td>cv.haveImageWriter(</td><td class="paramname">filename</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&gt;</code></p>
<p>Returns true if an image with the specified filename can be encoded by OpenCV. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filename</td><td>File name of the image </td></tr>
  </table>
  </dd>
</dl>
</div>
</div>
<a id="ga26a67788faa58ade337f8d28ba0eb19e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga26a67788faa58ade337f8d28ba0eb19e">◆ </a></span>imdecode() <span class="overload">[1/2]</span></h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> cv::imdecode </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">InputArray</a> </td>
          <td class="paramname"><em>buf</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int </td>
          <td class="paramname"><em>flags</em> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>retval</td><td>=</td><td>cv.imdecode(</td><td class="paramname">buf, flags</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&gt;</code></p>
<p>Reads an image from a buffer in memory. </p>
<p>The function imdecode reads an image from the specified buffer in the memory. If the buffer is too short or contains invalid data, the function returns an empty matrix ( <a class="el" href="../../d3/d63/classcv_1_1Mat.html#a4d33bed1c850265370d2af0ff02e1564" title="pointer to the data ">Mat::data</a>==NULL ).</p>
<p>See <a class="el" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56" title="Loads an image from a file. ">cv::imread</a> for the list of supported formats and flags description.</p>
<dl class="section note"><dt>Note</dt><dd>In the case of color images, the decoded images will have the channels stored in <b>B G R</b> order. </dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">buf</td><td>Input array or vector of bytes. </td></tr>
    <tr><td class="paramname">flags</td><td>The same flags as in <a class="el" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56" title="Loads an image from a file. ">cv::imread</a>, see <a class="el" href="../../d8/d6a/group__imgcodecs__flags.html#ga61d9b0126a3e57d9277ac48327799c80" title="Imread flags. ">cv::ImreadModes</a>. </td></tr>
  </table>
  </dd>
</dl>
</div>
</div>
<a id="ga5a0acefe5cbe0a81e904e452ec7ca733"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga5a0acefe5cbe0a81e904e452ec7ca733">◆ </a></span>imdecode() <span class="overload">[2/2]</span></h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> cv::imdecode </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">InputArray</a> </td>
          <td class="paramname"><em>buf</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int </td>
          <td class="paramname"><em>flags</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> * </td>
          <td class="paramname"><em>dst</em> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>retval</td><td>=</td><td>cv.imdecode(</td><td class="paramname">buf, flags</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&gt;</code></p>
<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. </p><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">buf</td><td></td></tr>
    <tr><td class="paramname">flags</td><td></td></tr>
    <tr><td class="paramname">dst</td><td>The optional output placeholder for the decoded matrix. It can save the image reallocations when the function is called repeatedly for images of the same size. </td></tr>
  </table>
  </dd>
</dl>
</div>
</div>
<a id="ga461f9ac09887e47797a54567df3b8b63"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga461f9ac09887e47797a54567df3b8b63">◆ </a></span>imencode()</h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool cv::imencode </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp; </td>
          <td class="paramname"><em>ext</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">InputArray</a> </td>
          <td class="paramname"><em>img</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">std::vector&lt; <a class="el" href="../../d1/d1b/group__core__hal__interface.html#ga65f85814a8290f9797005d3b28e7e5fc">uchar</a> &gt; &amp; </td>
          <td class="paramname"><em>buf</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const std::vector&lt; int &gt; &amp; </td>
          <td class="paramname"><em>params</em> = <code>std::vector&lt; int &gt;()</code> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>retval, buf</td><td>=</td><td>cv.imencode(</td><td class="paramname">ext, img[, params]</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&gt;</code></p>
<p>Encodes an image into a memory buffer. </p>
<p>The function imencode compresses the image and stores it in the memory buffer that is resized to fit the result. See <a class="el" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce" title="Saves an image to a specified file. ">cv::imwrite</a> for the list of supported formats and flags description.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">ext</td><td>File extension that defines the output format. </td></tr>
    <tr><td class="paramname">img</td><td>Image to be written. </td></tr>
    <tr><td class="paramname">buf</td><td>Output buffer resized to fit the compressed image. </td></tr>
    <tr><td class="paramname">params</td><td>Format-specific parameters. See <a class="el" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce" title="Saves an image to a specified file. ">cv::imwrite</a> and <a class="el" href="../../d8/d6a/group__imgcodecs__flags.html#ga292d81be8d76901bff7988d18d2b42ac" title="Imwrite flags. ">cv::ImwriteFlags</a>. </td></tr>
  </table>
  </dd>
</dl>
</div>
</div>
<a id="ga288b8b3da0892bd651fce07b3bbd3a56"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga288b8b3da0892bd651fce07b3bbd3a56">◆ </a></span>imread()</h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> cv::imread </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp; </td>
          <td class="paramname"><em>filename</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int </td>
          <td class="paramname"><em>flags</em> = <code><a class="el" href="../../d8/d6a/group__imgcodecs__flags.html#gga61d9b0126a3e57d9277ac48327799c80af660544735200cbe942eea09232eb822">IMREAD_COLOR</a></code> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>retval</td><td>=</td><td>cv.imread(</td><td class="paramname">filename[, flags]</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&gt;</code></p>
<p>Loads an image from a file. </p>
<p><a class="anchor" id="imread"></a> The function imread loads an image from the specified file and returns it. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format), the function returns an empty matrix ( <a class="el" href="../../d3/d63/classcv_1_1Mat.html#a4d33bed1c850265370d2af0ff02e1564" title="pointer to the data ">Mat::data</a>==NULL ).</p>
<p>Currently, the following file formats are supported:</p>
<ul>
<li>Windows bitmaps - *.bmp, *.dib (always supported)</li>
<li>JPEG files - *.jpeg, *.jpg, *.jpe (see the <em>Note</em> section)</li>
<li>JPEG 2000 files - *.jp2 (see the <em>Note</em> section)</li>
<li>Portable Network Graphics - *.png (see the <em>Note</em> section)</li>
<li>WebP - *.webp (see the <em>Note</em> section)</li>
<li>Portable image format - *.pbm, *.pgm, *.ppm *.pxm, *.pnm (always supported)</li>
<li>PFM files - *.pfm (see the <em>Note</em> section)</li>
<li>Sun rasters - *.sr, *.ras (always supported)</li>
<li>TIFF files - *.tiff, *.tif (see the <em>Note</em> section)</li>
<li>OpenEXR Image files - *.exr (see the <em>Note</em> section)</li>
<li>Radiance HDR - *.hdr, *.pic (always supported)</li>
<li>Raster and Vector geospatial data supported by GDAL (see the <em>Note</em> section)</li>
</ul>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The function determines the type of an image by the content, not by the file extension.</li>
<li>In the case of color images, the decoded images will have the channels stored in <b>B G R</b> order.</li>
<li>When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available. Results may differ to the output of <a class="el" href="../../d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab" title="Converts an image from one color space to another. ">cvtColor()</a></li>
<li>On Microsoft Windows* OS and MacOSX*, the codecs shipped with an OpenCV image (libjpeg, libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware that currently these native image loaders give images with different pixel values because of the color management embedded into MacOSX.</li>
<li>On Linux*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for codecs supplied with an OS image. Install the relevant packages (do not forget the development files, for example, "libjpeg-dev", in Debian* and Ubuntu*) to get the codec support or turn on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake.</li>
<li>In the case you set <em>WITH_GDAL</em> flag to true in CMake and <a class="el" href="../../d8/d6a/group__imgcodecs__flags.html#gga61d9b0126a3e57d9277ac48327799c80a1b482916f4ffe34f0b90550f267fd896">IMREAD_LOAD_GDAL</a> to load the image, then the <a href="http://www.gdal.org">GDAL</a> driver will be used in order to decode the image, supporting the following formats: <a href="http://www.gdal.org/formats_list.html">Raster</a>, <a href="http://www.gdal.org/ogr_formats.html">Vector</a>.</li>
<li>If EXIF information is embedded in the image file, the EXIF orientation will be taken into account and thus the image will be rotated accordingly except if the flags <a class="el" href="../../d8/d6a/group__imgcodecs__flags.html#gga61d9b0126a3e57d9277ac48327799c80a34f91a514cd95127d8ba900840af548e">IMREAD_IGNORE_ORIENTATION</a> or <a class="el" href="../../d8/d6a/group__imgcodecs__flags.html#gga61d9b0126a3e57d9277ac48327799c80aeddd67043ed0df14f9d9a4e66d2b0708">IMREAD_UNCHANGED</a> are passed.</li>
<li>Use the IMREAD_UNCHANGED flag to keep the floating point values from PFM image.</li>
<li>By default number of pixels must be less than 2^30. Limit can be set using system variable OPENCV_IO_MAX_IMAGE_PIXELS</li>
</ul>
</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filename</td><td>Name of file to be loaded. </td></tr>
    <tr><td class="paramname">flags</td><td>Flag that can take values of <a class="el" href="../../d8/d6a/group__imgcodecs__flags.html#ga61d9b0126a3e57d9277ac48327799c80" title="Imread flags. ">cv::ImreadModes</a> </td></tr>
  </table>
  </dd>
</dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="../../d1/d9e/fld_lines_8cpp-example.html#a6">fld_lines.cpp</a>, <a class="el" href="../../d0/d38/modules_2shape_2samples_2shape_example_8cpp-example.html#a13">modules/shape/samples/shape_example.cpp</a>, <a class="el" href="../../de/d01/samples_2cpp_2connected_components_8cpp-example.html#a13">samples/cpp/connected_components.cpp</a>, <a class="el" href="../../db/d75/samples_2cpp_2create_mask_8cpp-example.html#a21">samples/cpp/create_mask.cpp</a>, <a class="el" href="../../da/d53/samples_2cpp_2demhist_8cpp-example.html#a22">samples/cpp/demhist.cpp</a>, <a class="el" href="../../d4/dc6/samples_2cpp_2distrans_8cpp-example.html#a20">samples/cpp/distrans.cpp</a>, <a class="el" href="../../d6/d56/samples_2cpp_2edge_8cpp-example.html#a11">samples/cpp/edge.cpp</a>, <a class="el" href="../../d4/d26/samples_2cpp_2facedetect_8cpp-example.html#a14">samples/cpp/facedetect.cpp</a>, <a class="el" href="../../d2/dcf/samples_2cpp_2falsecolor_8cpp-example.html#a25">samples/cpp/falsecolor.cpp</a>, <a class="el" href="../../d1/d17/samples_2cpp_2ffilldemo_8cpp-example.html#a18">samples/cpp/ffilldemo.cpp</a>, <a class="el" href="../../d9/d73/samples_2cpp_2fitellipse_8cpp-example.html#a39">samples/cpp/fitellipse.cpp</a>, <a class="el" href="../../d8/d34/samples_2cpp_2grabcut_8cpp-example.html#a41">samples/cpp/grabcut.cpp</a>, <a class="el" href="../../dd/d93/samples_2cpp_2image_alignment_8cpp-example.html#a21">samples/cpp/image_alignment.cpp</a>, <a class="el" href="../../d3/db0/samples_2cpp_2pca_8cpp-example.html#a3">samples/cpp/pca.cpp</a>, <a class="el" href="../../db/d00/samples_2cpp_2squares_8cpp-example.html#a26">samples/cpp/squares.cpp</a>, <a class="el" href="../../db/db4/samples_2cpp_2stitching_8cpp-example.html#a2">samples/cpp/stitching.cpp</a>, <a class="el" href="../../d9/dd8/samples_2cpp_2stitching_detailed_8cpp-example.html#a5">samples/cpp/stitching_detailed.cpp</a>, <a class="el" href="../../d0/df8/samples_2cpp_2train_HOG_8cpp-example.html#a17">samples/cpp/train_HOG.cpp</a>, <a class="el" href="../../de/d45/samples_2cpp_2tutorial_code_2features2D_2Homography_2decompose_homography_8cpp-example.html#a8">samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp</a>, <a class="el" href="../../d9/d47/samples_2cpp_2tutorial_code_2features2D_2Homography_2homography_from_camera_displacement_8cpp-example.html#a8">samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp</a>, <a class="el" href="../../d0/d92/samples_2cpp_2tutorial_code_2features2D_2Homography_2pose_from_homography_8cpp-example.html#a7">samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp</a>, <a class="el" href="../../dc/dbc/samples_2cpp_2tutorial_code_2HighGUI_2AddingImagesTrackbar_8cpp-example.html#a3">samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp</a>, <a class="el" href="../../d8/ded/samples_2cpp_2tutorial_code_2Histograms_Matching_2MatchTemplate_Demo_8cpp-example.html#a2">samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp</a>, <a class="el" href="../../df/d5e/samples_2cpp_2tutorial_code_2ImgProc_2Morphology_1_8cpp-example.html#a2">samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp</a>, <a class="el" href="../../da/d34/samples_2cpp_2tutorial_code_2ImgProc_2Morphology_2_8cpp-example.html#a2">samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp</a>, <a class="el" href="../../d3/d08/samples_2cpp_2tutorial_code_2ImgProc_2Pyramids_2Pyramids_8cpp-example.html#a1">samples/cpp/tutorial_code/ImgProc/Pyramids/Pyramids.cpp</a>, <a class="el" href="../../d3/d8f/samples_2cpp_2tutorial_code_2ImgProc_2Smoothing_2Smoothing_8cpp-example.html#a3">samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp</a>, <a class="el" href="../../d6/d14/samples_2cpp_2tutorial_code_2ImgTrans_2copyMakeBorder_demo_8cpp-example.html#a3">samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp</a>, <a class="el" href="../../d1/de6/samples_2cpp_2tutorial_code_2ImgTrans_2houghcircles_8cpp-example.html#a1">samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp</a>, <a class="el" href="../../d5/df9/samples_2cpp_2tutorial_code_2ImgTrans_2houghlines_8cpp-example.html#a1">samples/cpp/tutorial_code/ImgTrans/houghlines.cpp</a>, <a class="el" href="../../d3/d94/samples_2cpp_2tutorial_code_2ImgTrans_2Sobel_Demo_8cpp-example.html#a6">samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp</a>, <a class="el" href="../../da/d94/samples_2cpp_2tutorial_code_2ml_2introduction_to_pca_2introduction_to_pca_8cpp-example.html#a23">samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp</a>, <a class="el" href="../../de/dd9/samples_2cpp_2tutorial_code_2photo_2non_photorealistic_rendering_2npr_demo_8cpp-example.html#a2">samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp</a>, <a class="el" href="../../dc/d23/samples_2cpp_2tutorial_code_2photo_2seamless_cloning_2cloning_demo_8cpp-example.html#a1">samples/cpp/tutorial_code/photo/seamless_cloning/cloning_demo.cpp</a>, <a class="el" href="../../de/dd4/samples_2cpp_2warpPerspective_demo_8cpp-example.html#a6">samples/cpp/warpPerspective_demo.cpp</a>, <a class="el" href="../../d4/d40/samples_2cpp_2watershed_8cpp-example.html#a17">samples/cpp/watershed.cpp</a>, <a class="el" href="../../d6/d39/samples_2dnn_2colorization_8cpp-example.html#a4">samples/dnn/colorization.cpp</a>, <a class="el" href="../../d7/d4f/samples_2dnn_2openpose_8cpp-example.html#a8">samples/dnn/openpose.cpp</a>, <a class="el" href="../../d8/d61/samples_2tapi_2hog_8cpp-example.html#a18">samples/tapi/hog.cpp</a>, and <a class="el" href="../../de/dc0/samples_2tapi_2squares_8cpp-example.html#a43">samples/tapi/squares.cpp</a>.</dd>
</dl>
</div>
</div>
<a id="ga4dd47c9ae3d55cc42286cff005825e31"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga4dd47c9ae3d55cc42286cff005825e31">◆ </a></span>imreadmulti()</h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool cv::imreadmulti </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp; </td>
          <td class="paramname"><em>filename</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">std::vector&lt; <a class="el" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &gt; &amp; </td>
          <td class="paramname"><em>mats</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int </td>
          <td class="paramname"><em>flags</em> = <code><a class="el" href="../../d8/d6a/group__imgcodecs__flags.html#gga61d9b0126a3e57d9277ac48327799c80ab6573b69300c092b61800222fe555953">IMREAD_ANYCOLOR</a></code> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>retval, mats</td><td>=</td><td>cv.imreadmulti(</td><td class="paramname">filename[, mats[, flags]]</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&gt;</code></p>
<p>Loads a multi-page image from a file. </p>
<p>The function imreadmulti loads a multi-page image from the specified file into a vector of <a class="el" href="../../d3/d63/classcv_1_1Mat.html" title="n-dimensional dense array class ">Mat</a> objects. </p><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filename</td><td>Name of file to be loaded. </td></tr>
    <tr><td class="paramname">flags</td><td>Flag that can take values of <a class="el" href="../../d8/d6a/group__imgcodecs__flags.html#ga61d9b0126a3e57d9277ac48327799c80" title="Imread flags. ">cv::ImreadModes</a>, default with <a class="el" href="../../d8/d6a/group__imgcodecs__flags.html#gga61d9b0126a3e57d9277ac48327799c80ab6573b69300c092b61800222fe555953" title="If set, the image is read in any possible color format. ">cv::IMREAD_ANYCOLOR</a>. </td></tr>
    <tr><td class="paramname">mats</td><td>A vector of <a class="el" href="../../d3/d63/classcv_1_1Mat.html" title="n-dimensional dense array class ">Mat</a> objects holding each page, if more than one. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56" title="Loads an image from a file. ">cv::imread</a> </dd></dl>
</div>
</div>
<a id="gabbc7ef1aa2edfaa87772f1202d67e0ce"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gabbc7ef1aa2edfaa87772f1202d67e0ce">◆ </a></span>imwrite()</h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool cv::imwrite </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp; </td>
          <td class="paramname"><em>filename</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">InputArray</a> </td>
          <td class="paramname"><em>img</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const std::vector&lt; int &gt; &amp; </td>
          <td class="paramname"><em>params</em> = <code>std::vector&lt; int &gt;()</code> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>retval</td><td>=</td><td>cv.imwrite(</td><td class="paramname">filename, img[, params]</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&gt;</code></p>
<p>Saves an image to a specified file. </p>
<p>The function imwrite saves the image to the specified file. The image format is chosen based on the filename extension (see <a class="el" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56" title="Loads an image from a file. ">cv::imread</a> for the list of extensions). In general, only 8-bit single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function, with these exceptions:</p>
<ul>
<li>16-bit unsigned (CV_16U) images can be saved in the case of PNG, JPEG 2000, and TIFF formats</li>
<li>32-bit float (CV_32F) images can be saved in PFM, TIFF, OpenEXR, and Radiance HDR formats; 3-channel (CV_32FC3) TIFF images will be saved using the LogLuv high dynamic range encoding (4 bytes per pixel)</li>
<li>PNG images with an alpha channel can be saved using this function. To do this, create 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535 (see the code sample below).</li>
<li>Multiple images (vector of <a class="el" href="../../d3/d63/classcv_1_1Mat.html" title="n-dimensional dense array class ">Mat</a>) can be saved in TIFF format (see the code sample below).</li>
</ul>
<p>If the format, depth or channel order is different, use <a class="el" href="../../d3/d63/classcv_1_1Mat.html#adf88c60c5b4980e05bb556080916978b" title="Converts an array to another data type with optional scaling. ">Mat::convertTo</a> and <a class="el" href="../../d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab" title="Converts an image from one color space to another. ">cv::cvtColor</a> to convert it before saving. Or, use the universal <a class="el" href="../../da/d56/classcv_1_1FileStorage.html" title="XML/YAML/JSON file storage class that encapsulates all the information necessary for writing or readi...">FileStorage</a> I/O functions to save the image to XML or YAML format.</p>
<p>The sample below shows how to create a BGRA image, how to set custom compression parameters and save it to a PNG file. It also demonstrates how to save multiple images in a TIFF file: </p><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d8/dcc/namespacestd.html">std</a>;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> paintAlphaMat(<a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &amp;mat)</div><div class="line">{</div><div class="line">    <a class="code" href="../../db/de0/group__core__utils.html#gaf62bcd90f70e275191ab95136d85906b">CV_Assert</a>(mat.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa11336b9ac538e0475d840657ce164be">channels</a>() == 4);</div><div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; mat.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a>; ++i)</div><div class="line">    {</div><div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j &lt; mat.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a>; ++j)</div><div class="line">        {</div><div class="line">            <a class="code" href="../../d6/dcf/classcv_1_1Vec.html">Vec4b</a>&amp; bgra = mat.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa5d20fc86d41d59e4d71ae93daee9726">at</a>&lt;<a class="code" href="../../d6/dcf/classcv_1_1Vec.html">Vec4b</a>&gt;(i, j);</div><div class="line">            bgra[0] = UCHAR_MAX; <span class="comment">// Blue</span></div><div class="line">            bgra[1] = <a class="code" href="../../db/de0/group__core__utils.html#gab93126370b85fda2c8bfaf8c811faeaf">saturate_cast</a>&lt;<a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga65f85814a8290f9797005d3b28e7e5fc">uchar</a>&gt;((float (mat.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a> - j)) / ((<span class="keywordtype">float</span>)mat.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a>) * UCHAR_MAX); <span class="comment">// Green</span></div><div class="line">            bgra[2] = <a class="code" href="../../db/de0/group__core__utils.html#gab93126370b85fda2c8bfaf8c811faeaf">saturate_cast</a>&lt;<a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga65f85814a8290f9797005d3b28e7e5fc">uchar</a>&gt;((float (mat.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a> - i)) / ((<span class="keywordtype">float</span>)mat.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a>) * UCHAR_MAX); <span class="comment">// Red</span></div><div class="line">            bgra[3] = <a class="code" href="../../db/de0/group__core__utils.html#gab93126370b85fda2c8bfaf8c811faeaf">saturate_cast</a>&lt;<a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga65f85814a8290f9797005d3b28e7e5fc">uchar</a>&gt;(0.5 * (bgra[1] + bgra[2])); <span class="comment">// Alpha</span></div><div class="line">        }</div><div class="line">    }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main()</div><div class="line">{</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> mat(480, 640, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga4519ad2827f771db8260c61207b782df">CV_8UC4</a>); <span class="comment">// Create a matrix with alpha channel</span></div><div class="line">    paintAlphaMat(mat);</div><div class="line"></div><div class="line">    vector&lt;int&gt; compression_params;</div><div class="line">    compression_params.push_back(<a class="code" href="../../d8/d6a/group__imgcodecs__flags.html#gga292d81be8d76901bff7988d18d2b42acad2548321c69ab9c0582fd51e75ace1d0">IMWRITE_PNG_COMPRESSION</a>);</div><div class="line">    compression_params.push_back(9);</div><div class="line"></div><div class="line">    <span class="keywordtype">bool</span> result = <span class="keyword">false</span>;</div><div class="line">    <span class="keywordflow">try</span></div><div class="line">    {</div><div class="line">        result = <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(<span class="stringliteral">"alpha.png"</span>, mat, compression_params);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="../../d1/dee/classcv_1_1Exception.html">cv::Exception</a>&amp; ex)</div><div class="line">    {</div><div class="line">        fprintf(stderr, <span class="stringliteral">"Exception converting image to PNG format: %s\n"</span>, ex.<a class="code" href="../../d1/dee/classcv_1_1Exception.html#a9c1e692401016807255e0e6ad562ece9">what</a>());</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (result)</div><div class="line">        printf(<span class="stringliteral">"Saved PNG file with alpha data.\n"</span>);</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">        printf(<span class="stringliteral">"ERROR: Can't save PNG file.\n"</span>);</div><div class="line"></div><div class="line">    vector&lt;Mat&gt; imgs;</div><div class="line">    imgs.push_back(mat);</div><div class="line">    imgs.push_back(~mat);</div><div class="line">    imgs.push_back(mat(<a class="code" href="../../dc/d84/group__core__basic.html#ga11d95de507098e90bad732b9345402e8">Rect</a>(0, 0, mat.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a> / 2, mat.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#abed816466c45234254d25bc59c31245e">rows</a> / 2)));</div><div class="line">    <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">imwrite</a>(<span class="stringliteral">"test.tiff"</span>, imgs);</div><div class="line">    printf(<span class="stringliteral">"Multiple files saved in test.tiff\n"</span>);</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> result ? 0 : 1;</div><div class="line">}</div></div><!-- fragment --> <dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">filename</td><td>Name of the file. </td></tr>
    <tr><td class="paramname">img</td><td>(<a class="el" href="../../d3/d63/classcv_1_1Mat.html" title="n-dimensional dense array class ">Mat</a> or vector of <a class="el" href="../../d3/d63/classcv_1_1Mat.html" title="n-dimensional dense array class ">Mat</a>) Image or Images to be saved. </td></tr>
    <tr><td class="paramname">params</td><td>Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see <a class="el" href="../../d8/d6a/group__imgcodecs__flags.html#ga292d81be8d76901bff7988d18d2b42ac" title="Imwrite flags. ">cv::ImwriteFlags</a> </td></tr>
  </table>
  </dd>
</dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="../../dd/d93/samples_2cpp_2image_alignment_8cpp-example.html#a45">samples/cpp/image_alignment.cpp</a>, <a class="el" href="../../db/db4/samples_2cpp_2stitching_8cpp-example.html#a1">samples/cpp/stitching.cpp</a>, <a class="el" href="../../d9/dd8/samples_2cpp_2stitching_detailed_8cpp-example.html#a66">samples/cpp/stitching_detailed.cpp</a>, <a class="el" href="../../dc/d23/samples_2cpp_2tutorial_code_2photo_2seamless_cloning_2cloning_demo_8cpp-example.html#a10">samples/cpp/tutorial_code/photo/seamless_cloning/cloning_demo.cpp</a>, <a class="el" href="../../d8/d61/samples_2tapi_2hog_8cpp-example.html#a38">samples/tapi/hog.cpp</a>, and <a class="el" href="../../de/dc0/samples_2tapi_2squares_8cpp-example.html#a50">samples/tapi/squares.cpp</a>.</dd>
</dl>
</div>
</div>
<a id="ga506e85114c8b4340bb12eca5080205d2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga506e85114c8b4340bb12eca5080205d2">◆ </a></span>imwritemulti()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">static bool cv::imwritemulti </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> &amp; </td>
          <td class="paramname"><em>filename</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#ga606feabe3b50ab6838f1ba89727aa07a">InputArrayOfArrays</a> </td>
          <td class="paramname"><em>img</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const std::vector&lt; int &gt; &amp; </td>
          <td class="paramname"><em>params</em> = <code>std::vector&lt;int&gt;()</code> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">static</span></span>  </td>
  </tr>
</table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>retval</td><td>=</td><td>cv.imwritemulti(</td><td class="paramname">filename, img[, params]</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d6/d87/imgcodecs_8hpp.html">opencv2/imgcodecs.hpp</a>&gt;</code></p>
<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. </p>
</div>
</div>
</div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:40 for OpenCV by  <a href="http://www.doxygen.org/index.html">
<img alt="doxygen" class="footer" src="../../doxygen.png"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
